package com.huawei.appgallery.foundation.ui.framework.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;
import huawei.widget.HwButton;
import o.azb;
import o.epv;

public class BottomButton extends HwButton {
    private static String ॱ = "BottomButton";
    private String ʼ = null;
    private int ˊ = ((azb.ॱ(getContext()) - azb.ˊ(getContext())) - azb.ˏ(getContext()));
    private int ˋ = epv.ˋ(getContext(), 8);
    private int ˎ = (epv.ˎ(getContext()) / 2);
    private int ˏ = epv.ˋ(getContext(), 8);

    public BottomButton(Context context) {
        super(context, null);
    }

    public BottomButton(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public BottomButton(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        ˏ();
    }

    private synchronized void ˏ() {
        this.ʼ = ˎ();
        int ˏ = ˏ(getContext(), this.ʼ, (float) epv.ˎ(getContext(), getTextSize()), true);
        if (this.ʼ != null && this.ʼ.length() > 0) {
            ˊ(ˏ);
        }
    }

    private String ˎ() {
        String str = "";
        CharSequence text = getText();
        if (text != null) {
            return text.toString();
        }
        return str;
    }

    private void ˊ(int i) {
        LayoutParams layoutParams = getLayoutParams();
        if (layoutParams != null) {
            int i2 = (this.ˋ + i) + this.ˏ;
            if (i2 >= this.ˎ && i2 <= this.ˊ) {
                layoutParams.width = i2;
            } else if (i2 > this.ˊ) {
                layoutParams.width = this.ˊ;
            } else {
                layoutParams.width = this.ˎ;
            }
            setLayoutParams(layoutParams);
        }
    }

    private int ˏ(Context context, String str, float f, boolean z) {
        if (context == null || str == null || str.isEmpty() || 0.0f == f) {
            return 0;
        }
        TextView textView = new TextView(context);
        textView.setText(str);
        textView.setTextSize(f);
        textView.setSingleLine(true);
        textView.measure(-2, -2);
        int measuredWidth = textView.getMeasuredWidth();
        int measuredHeight = textView.getMeasuredHeight();
        if (z) {
            return measuredWidth;
        }
        return measuredHeight;
    }
}
